The Civic Auth Solana API for React Native is currently in early access and
subject to change.
Getting Started
After authenticating a user with Civic Auth, you can create a Web3 wallet for them using theuseWeb3Client hook. Embedded wallets are generated on behalf of users through our non-custodial wallet partner—neither Civic nor your app has access to the private keys.
Only embedded wallets are supported (no self-custodial wallet connections yet)
Installation
Install the SDK and its peer dependencies:- npm
- yarn
- pnpm
bash npm install @civic/react-native-auth-web3 @solana/web3.js Native Setup
Android Configuration
Add the following to yourandroid/app/build.gradle:
iOS Configuration
Requirements:- iOS 14.0 or higher
- Xcode 14.0 or higher
- Swift 5.0 or higher
- Navigate to the Info tab of your app target settings in Xcode
- In the URL Types section, click the + button to add a new URL
- Enter the following values:
- Identifier:
metakeep - URL Schemes:
$(PRODUCT_BUNDLE_IDENTIFIER)
- Identifier:
ios/<YourAppName>/AppDelegate.swift:
How Wallet Creation Works
After authenticating with Civic Auth, the SDK can create a non-custodial embedded wallet for the user. The creation process requires an ID token - a JWT received from Civic Auth after successful authentication. This token proves the user’s identity and links the wallet to their Civic account. Without a valid ID token, wallet creation will fail. This ensures only authenticated users can create wallets, with each wallet uniquely tied to a specific user account.Quick Start
The useWeb3Client Hook
TheuseWeb3Client hook returns a Web3Client object for interacting with blockchain networks. The client manages both wallet creation and transaction operations.
Web3Client Interface
SolanaWeb3Client Methods
Thesolana property provides access to Solana-specific operations:
Using the Wallet
Sending Transactions
You have two options for sending transactions:Option 1: Simple Transfer (Recommended)
UsesendTransaction for quick SOL transfers. It handles transaction creation, signing, and broadcasting:
Option 2: Custom Transactions
UsesignTransaction for complex transactions with custom instructions:
Checking Balance
Signing Messages
Complete Example
Here’s a complete authentication provider with Expo Auth Session and Web3 wallet creation:Example Repository
For a complete working example of Civic Auth with embedded wallets in a React Native application, check out our example repository: [https://github.com/civicteam/civic-auth-examples/tree/main/packages/mobile/react-native-expo]Crypto Polyfill
The SDK automatically includes a crypto polyfill using expo-crypto to provide thegetRandomValues function required by Solana’s PublicKey object. This polyfill ensures cryptographic operations work correctly in React Native environments where the Web Crypto API is not natively available.
The polyfill is applied automatically when you import the SDK, so no additional configuration is needed.
